//
//  WeatherTableViewCell.m
//  SoutheastAsia
//
//  Created by rimi on 16/1/8.
//  Copyright © 2016年 zlj. All rights reserved.
//

#import "WeatherTableViewCell.h"

@interface WeatherTableViewCell ()

@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *highTemperature;
@property (nonatomic, strong) NSString *lowTemperature;
@property (nonatomic, strong) UIImage *wetherImage;
@property (nonatomic, strong) UIImage *HighCentigradeImage;
@property (nonatomic, strong) UIImage *lowCentigradeImage;
@end

@implementation WeatherTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.180];
    }
    return self;
}

- (void)loadDataList:(NSMutableDictionary *)datalist {
    self.title = [datalist[@"date"] substringFromIndex:5];
    self.highTemperature = datalist[@"tmp"][@"max"];
    self.lowTemperature = datalist[@"tmp"][@"min"];
    self.HighCentigradeImage = [UIImage imageNamed:@"摄氏度.png"];
    self.lowCentigradeImage = [UIImage imageNamed:@"摄氏度.png"];
    
    if ([datalist[@"cond"][@"txt_d"] rangeOfString:@"Sunny"].location != NSNotFound) {
        self.wetherImage = [UIImage imageNamed:@"晴.png"];
    } else if ([datalist[@"cond"][@"txt_d"] rangeOfString:@"Cloudy"].location != NSNotFound) {
        self.wetherImage = [UIImage imageNamed:@"多云.png"];
    } else if ([datalist[@"cond"][@"txt_d"] rangeOfString:@"Rain"].location != NSNotFound) {
        self.wetherImage = [UIImage imageNamed:@"雨.png"];
    } else if ([datalist[@"cond"][@"txt_d"] rangeOfString:@"Overcast"].location != NSNotFound) {
        self.wetherImage = [UIImage imageNamed:@"阴.png"];
    }
    
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
    [self.title drawInRect:CGRectMake(20, CGRectGetHeight(self.bounds) * 0.2, 80, 30) withAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:22], NSForegroundColorAttributeName: [UIColor whiteColor]}];

    [self.highTemperature drawInRect:CGRectMake(CGRectGetWidth(self.bounds) * 0.65, CGRectGetHeight(self.bounds) * 0.2, 30, 30) withAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:22], NSForegroundColorAttributeName: [UIColor whiteColor]}];
    [self.HighCentigradeImage drawInRect:CGRectMake(CGRectGetWidth(self.bounds) * 0.74, CGRectGetHeight(self.bounds) * 0.25, 8, 8)];
    
    [self.lowTemperature drawInRect:CGRectMake(CGRectGetWidth(self.bounds) * 0.85, CGRectGetHeight(self.bounds) * 0.2, 30, 30) withAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:22], NSForegroundColorAttributeName: [UIColor whiteColor]}];
    [self.lowCentigradeImage drawInRect:CGRectMake(CGRectGetWidth(self.bounds) * 0.93, CGRectGetHeight(self.bounds) * 0.25, 8, 8)];

    [self.wetherImage drawInRect:CGRectMake(CGRectGetWidth(self.bounds) * 0.45, CGRectGetHeight(self.bounds) * 0.2, 30, 30)];
}

@end
